//
//  HTCancelItem.m
//  TruckUser
//
//  Created by Ting Han on 2017/11/1.
//  Copyright © 2017年 Ting Han. All rights reserved.
//

#import "HTCancelItem.h"
#import "UIView+Layout.h"

@implementation HTCancelItem
- (instancetype)initWithCoder:(NSCoder *)coder
{
    self = [super initWithCoder:coder];
    if (self) {
        [self setupView];
    }
    return self;
}
- (void)setupView{
    self.iconImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 27, 27)];
    self.iconImageView.contentMode = UIViewContentModeCenter;
    [self addSubview:self.iconImageView];
    self.titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(self.iconImageView.right+5, 0, 0, 0)];
    self.titleLabel.font = [UIFont systemFontOfSize:13];
    self.titleLabel.centerY = self.iconImageView.centerY;
    [self.titleLabel sizeToFit];
    [self addSubview:self.titleLabel];
    self.isSelected = NO;
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(didTap)];
    [self addGestureRecognizer:tap];
}
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setupView];
    }
    return self;
}
- (void)didTap{
    if (self.delegate && [self.delegate respondsToSelector:@selector(didClickItem:)]) {
        [self.delegate didClickItem:self];
    }
}
- (void)setIsSelected:(BOOL)isSelected{
    _isSelected = isSelected;
    if (isSelected) {
        self.iconImageView.image = [UIImage imageNamed:@"cashier_select_pressed"];
    }else{
         self.iconImageView.image = [UIImage imageNamed:@"cashier_select_normal"];
    }
    
}
- (void)setTitle:(NSString *)title{
    _title = title;
    self.titleLabel.text = title;
    [self.titleLabel sizeToFit];
    self.titleLabel.centerY = self.iconImageView.centerY;
}
@end
